package com.jie.controller;


import com.jie.dto.MenuDTO;
import com.jie.dto.UserMenuDTO;
import com.jie.entity.Menu;
import com.jie.service.MenuService;
import com.jie.util.RespBean;
import com.jie.vo.ConditionVO;
import com.jie.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2022-01-04
 */
@RestController
@RequestMapping("/system/cfg")
@Api(tags = "菜单模块")
public class MenuController {

    @Autowired
    private MenuService menuService;
    /**
     * 查询菜单列表
     *
     * @param conditionVO 条件
     * @return {@link RespBean<MenuDTO>} 菜单列表
     */
    @ApiOperation(value = "查看菜单列表")
    @GetMapping("/admin/listMenus")
    public RespBean<List<MenuDTO>> listMenus(ConditionVO conditionVO) {
        return RespBean.success("listMenus",menuService.listMenus(conditionVO));
    }

    @ApiOperation(value = "通过角色查询菜单列表")
    @GetMapping("/menu")
    public List<Menu> gentMenusByAdminId(){
        return menuService.getMenusWithRole();
    }
    /**
     * 查看当前用户菜单
     *
     * @return  菜单列表
     */
    @ApiOperation(value = "查看当前用户查询菜单")
    @GetMapping("/user/menus")
    public List<UserMenuDTO> listUserMenus() {
        return menuService.listUserMenus();
    }
    /**
     * 新增或修改菜单
     *
     * @param menuVO 菜单
     * @return  菜单列表
     */
    @ApiOperation(value = "新增或修改菜单")
    @PostMapping("/admin/menus")
    public RespBean<?> saveOrUpdateMenu(@Valid @RequestBody MenuVO menuVO) {
        menuService.saveOrUpdateMenu(menuVO);
        return RespBean.success("新增或修改菜单成功");
    }
}

